package hw1_4;
import java.util.Scanner;

public class Main {
    // 用来记录所有参与者评分的总和
    static int totalScore = 0;
    // 用来记录两队实力差的最小绝对值，初始化为最大整数值，以便后续比较
    static int minDiff = Integer.MAX_VALUE;

    // 计算组合得分的函数
    static void calculateScore(int[] scores, boolean[] used, int start, int depth) {
        // 如果已选出5个成员，则开始计算分差
        if (depth == 5) {
            int teamScore = 0;
            // 计算当前组合的评分总和
            for (int i = 0; i < 10; i++) {
                if (used[i]) teamScore += scores[i];
            }
            // 计算并更新最小分差
            int diff = Math.abs(totalScore - 2 * teamScore);
            minDiff = Math.min(minDiff, diff);
            return;
        }
        // 从start开始，选择下一个队员，避免重复选择
        for (int i = start; i < 10; i++) {
            used[i] = true;
            calculateScore(scores, used, i + 1, depth + 1);
            used[i] = false; // 回溯，撤销选择
        }
    }

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int[] scores = new int[10];
        // 循环读入参与者的评分，并计算总分
        for (int i = 0; i < 10; i++) {
            scores[i] = scanner.nextInt();
            totalScore += scores[i];
        }

        // 调用函数开始计算两队实力差的最小绝对值
        calculateScore(scores, new boolean[10], 0, 0);
        // 输出最小的实力差绝对值
        System.out.println(minDiff);
    }
}


